package com.seckill.monitor;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.seckill.goods.feign.SkuFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @program: seckill-parent
 * @description: 定时调用查询了热点数据
 * @author: zhanghz001
 * @create: 2021-06-29 17:56
 **/
// @ElasticSimpleJob(
//         jobName = "ZhzMonitorTask",
//         cron = "1/5 * * * * ?",
//         shardingTotalCount = 1
// )
// @Component
public class ZhzMonitorTask implements SimpleJob {
    @Autowired
    private SkuFeign skuFeign;
    @Autowired
    private MonitorItemsAccess monitorItemsAccess;
    
    @Override
    public void execute(ShardingContext shardingContext) {
        try {
            List<String> ids = monitorItemsAccess.loadData();
            if (!CollectionUtils.isEmpty(ids)) {
                for (String id : ids) {
                    System.out.println("id: " + id);
                }
                skuFeign.hotIsolation(ids);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
